#ifndef THINK_THINK_CONFIG_H
#define THINK_THINK_CONFIG_H

static char* think_config =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think;\n"
	"\n"
	"class Config\n"
	"{\n"
	"    /**\n"
	"     * @var array 配置参数\n"
	"     */\n"
	"    private static $config = [];\n"
	"\n"
	"    /**\n"
	"     * @var string 参数作用域\n"
	"     */\n"
	"    private static $range = \'_sys_\';\n"
	"\n"
	"    /**\n"
	"     * 设定配置参数的作用域\n"
	"     * @access public\n"
	"     * @param  string $range 作用域\n"
	"     * @return void\n"
	"     */\n"
	"    public static function range($range)\n"
	"    {\n"
	"        self::$range = $range;\n"
	"\n"
	"        if (!isset(self::$config[$range])) self::$config[$range] = [];\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 解析配置文件或内容\n"
	"     * @access public\n"
	"     * @param  string $config 配置文件路径或内容\n"
	"     * @param  string $type   配置解析类型\n"
	"     * @param  string $name   配置名（如设置即表示二级配置）\n"
	"     * @param  string $range  作用域\n"
	"     * @return mixed\n"
	"     */\n"
	"    public static function parse($config, $type = \'\', $name = \'\', $range = \'\')\n"
	"    {\n"
	"        $range = $range ?: self::$range;\n"
	"\n"
	"        if (empty($type)) $type = pathinfo($config, PATHINFO_EXTENSION);\n"
	"\n"
	"        $class = false !== strpos($type, \'\\\\\') ?\n"
	"            $type :\n"
	"            \'\\\\think\\\\config\\\\driver\\\\\' . ucwords($type);\n"
	"\n"
	"        return self::set((new $class())->parse($config), $name, $range);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 加载配置文件（PHP格式）\n"
	"     * @access public\n"
	"     * @param  string $file  配置文件名\n"
	"     * @param  string $name  配置名（如设置即表示二级配置）\n"
	"     * @param  string $range 作用域\n"
	"     * @return mixed\n"
	"     */\n"
	"    public static function load($file, $name = \'\', $range = \'\')\n"
	"    {\n"
	"        $range = $range ?: self::$range;\n"
	"\n"
	"        if (!isset(self::$config[$range])) self::$config[$range] = [];\n"
	"\n"
	"        if (is_file($file)) {\n"
	"            $name = strtolower($name);\n"
	"            $type = pathinfo($file, PATHINFO_EXTENSION);\n"
	"\n"
	"            if (\'php\' == $type) {\n"
	"                return self::set(include $file, $name, $range);\n"
	"            }\n"
	"\n"
	"            if (\'yaml\' == $type && function_exists(\'yaml_parse_file\')) {\n"
	"                return self::set(yaml_parse_file($file), $name, $range);\n"
	"            }\n"
	"\n"
	"            return self::parse($file, $type, $name, $range);\n"
	"        }\n"
	"\n"
	"        return self::$config[$range];\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 检测配置是否存在\n"
	"     * @access public\n"
	"     * @param  string $name 配置参数名（支持二级配置 . 号分割）\n"
	"     * @param  string $range  作用域\n"
	"     * @return bool\n"
	"     */\n"
	"    public static function has($name, $range = \'\')\n"
	"    {\n"
	"        $range = $range ?: self::$range;\n"
	"\n"
	"        if (!strpos($name, \'.\')) {\n"
	"            return isset(self::$config[$range][strtolower($name)]);\n"
	"        }\n"
	"\n"
	"        // 二维数组设置和获取支持\n"
	"        $name = explode(\'.\', $name, 2);\n"
	"        return isset(self::$config[$range][strtolower($name[0])][$name[1]]);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取配置参数 为空则获取所有配置\n"
	"     * @access public\n"
	"     * @param  string $name 配置参数名（支持二级配置 . 号分割）\n"
	"     * @param  string $range  作用域\n"
	"     * @return mixed\n"
	"     */\n"
	"    public static function get($name = null, $range = \'\')\n"
	"    {\n"
	"        $range = $range ?: self::$range;\n"
	"\n"
	"        // 无参数时获取所有\n"
	"        if (empty($name) && isset(self::$config[$range])) {\n"
	"            return self::$config[$range];\n"
	"        }\n"
	"\n"
	"        // 非二级配置时直接返回\n"
	"        if (!strpos($name, \'.\')) {\n"
	"            $name = strtolower($name);\n"
	"            return isset(self::$config[$range][$name]) ? self::$config[$range][$name] : null;\n"
	"        }\n"
	"\n"
	"        // 二维数组设置和获取支持\n"
	"        $name    = explode(\'.\', $name, 2);\n"
	"        $name[0] = strtolower($name[0]);\n"
	"\n"
	"        if (!isset(self::$config[$range][$name[0]])) {\n"
	"            // 动态载入额外配置\n"
	"            $module = Request::instance()->module();\n"
	"            $file   = CONF_PATH . ($module ? $module . DS : \'\') . \'extra\' . DS . $name[0] . CONF_EXT;\n"
	"\n"
	"            is_file($file) && self::load($file, $name[0]);\n"
	"        }\n"
	"\n"
	"        return isset(self::$config[$range][$name[0]][$name[1]]) ?\n"
	"            self::$config[$range][$name[0]][$name[1]] :\n"
	"            null;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置配置参数 name 为数组则为批量设置\n"
	"     * @access public\n"
	"     * @param  string|array $name  配置参数名（支持二级配置 . 号分割）\n"
	"     * @param  mixed        $value 配置值\n"
	"     * @param  string       $range 作用域\n"
	"     * @return mixed\n"
	"     */\n"
	"    public static function set($name, $value = null, $range = \'\')\n"
	"    {\n"
	"        $range = $range ?: self::$range;\n"
	"\n"
	"        if (!isset(self::$config[$range])) self::$config[$range] = [];\n"
	"\n"
	"        // 字符串则表示单个配置设置\n"
	"        if (is_string($name)) {\n"
	"            if (!strpos($name, \'.\')) {\n"
	"                self::$config[$range][strtolower($name)] = $value;\n"
	"            } else {\n"
	"                // 二维数组\n"
	"                $name = explode(\'.\', $name, 2);\n"
	"                self::$config[$range][strtolower($name[0])][$name[1]] = $value;\n"
	"            }\n"
	"\n"
	"            return $value;\n"
	"        }\n"
	"\n"
	"        // 数组则表示批量设置\n"
	"        if (is_array($name)) {\n"
	"            if (!empty($value)) {\n"
	"                self::$config[$range][$value] = isset(self::$config[$range][$value]) ?\n"
	"                    array_merge(self::$config[$range][$value], $name) :\n"
	"                    $name;\n"
	"\n"
	"                return self::$config[$range][$value];\n"
	"            }\n"
	"\n"
	"            return self::$config[$range] = array_merge(\n"
	"                self::$config[$range], array_change_key_case($name)\n"
	"            );\n"
	"        }\n"
	"\n"
	"        // 为空直接返回已有配置\n"
	"        return self::$config[$range];\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 重置配置参数\n"
	"     * @access public\n"
	"     * @param  string $range 作用域\n"
	"     * @return void\n"
	"     */\n"
	"    public static function reset($range = \'\')\n"
	"    {\n"
	"        $range = $range ?: self::$range;\n"
	"\n"
	"        if (true === $range) {\n"
	"            self::$config = [];\n"
	"        } else {\n"
	"            self::$config[$range] = [];\n"
	"        }\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif